﻿package command {
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class ReplaceCommand implements ICommand {
		private var inputField:TextField;
		private var text:String;
		private var block:Array;
		private var format:Array;
		
		public function ReplaceCommand(inputField:TextField, text:String, block:Array, format:Array):void {
			this.inputField = inputField;
			this.text = text;
			this.block = block;
			this.format = format;
		}
		
		public function redo():void {
			inputField.replaceText(block[0], block[block.length - 1], "");
		}
		public function undo():void {
			inputField.replaceText(block[0], block[0], text);
			for (var i:int = 0, count:int = 0; i < block.length; i += 2, count++) {
				inputField.setTextFormat(format[count], block[i], block[i + 1]);
			}
		}
	}
}